package com.atguigu.gmall.cart.controller.feign;

import com.atguigu.gmall.cart.service.CartInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/***
 * 给远程调用的购物车的controller
 */
@RestController
@RequestMapping("/api/cart")
public class FeignCartInfoController {

    @Autowired
    private CartInfoService cartInfoService;

    /**
     * 用户下单成功，清空购物车
     * @return
     */
    @DeleteMapping("/clearCart")
    public Boolean clearCart(){
        try{
            //调用业务层方法
            return cartInfoService.clearCart();
        }catch (Exception e){
            e.printStackTrace();
        }
        return false;
    }

    /**
     * 获取用户购物车相关信息
     * @return
     */
    @GetMapping("/getOrderCartMap")
    public Map getOrderCartMap(){
        //调用业务层方法
         Map orderCartMap = cartInfoService.MapOrderCartMap();

         return orderCartMap;
    }
}
